package com.example.flutter_ad_demo

import android.content.Context
import com.bwt.top.AdSdk
import com.bwt.top.AdSdk.InitCallback
import com.bwt.top.util.ALog

class InitManager private constructor() {
    companion object {
        @JvmField
        val instance = InitManager()
    }

    private var inited = false

    var bwtInited = false
        private set
    var bwtInitSuccess = false
        private set
    var bwtInitCallback: InitCallback? = null

    fun init(ctx: Context) {
        if (inited) return

        val context = ctx.applicationContext
        if (BuildConfig.DEBUG) {
            ALog.openLog()
        }
        // 缩短⼴告的响应，提⾼曝光率，减少特定⻚⾯⼴告“闪⼊”的情况，建议开发者将初始化事件放在主⼊⼝或前置。
        AdSdk.getInstance().baseHttp = "http://ad.bwton.com"
        // TODO 替换成自己的APPID
        AdSdk.getInstance().init(context, "400805") {
            bwtInited = true
            bwtInitSuccess = it
            bwtInitCallback?.onInitResult(it)
        }
        inited = true
    }
}